package com.clms.marketings.controller;

import com.clms.common.R;
import com.clms.marketings.pojo.entity.TbAdvertise;
import com.clms.marketings.pojo.vo.AdvertiseVo;
import com.clms.marketings.pojo.vo.AdvertiseVoVo;
import com.clms.marketings.pojo.vo.CustomerIssuesVo;
import com.clms.marketings.pojo.vo.PositionVo;
import com.clms.marketings.service.TbAdvertiseService;
import com.clms.marketings.utils.UploadPicture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @program: clms-third
 * @description: 广告管理是控制层
 * @author: 赵露露
 * @create: 2021-07-23 17:00
 **/
@RestController
@RequestMapping("/marketing/advertise")
public class TbAdvertiseController {
    @Autowired
    private TbAdvertiseService tbAdvertiseService;
    //分页查询
    @PostMapping("/selectpage/{currentPage}/{pageSize}")
    public R selectPage(@PathVariable Integer currentPage,
                        @PathVariable Integer pageSize,
                        @RequestBody AdvertiseVo advertiseVo){
        return tbAdvertiseService.selectAll(currentPage,pageSize,advertiseVo);
    }
    //增加广告
    @PostMapping("insertadvertise")
    public R insertAdvertise(@RequestBody TbAdvertise tbAdvertise){
        return tbAdvertiseService.insertAdvertise(tbAdvertise);
    }
    //修改广告
    @PutMapping("updateadvertise")
    public R updateAdvertise(@RequestBody TbAdvertise tbAdvertise){
        return tbAdvertiseService.updateAdvertise(tbAdvertise);
    }
    //删除广告位置
    @DeleteMapping("deleteadvertise")
    public R deleteAdvertise(@RequestParam Integer id){
        return tbAdvertiseService.deleteAdvertise(id);
    }
    //根据id查广告位置
    @GetMapping("selectbyid/{id}")
    public R selectById(@PathVariable Integer id){
        return tbAdvertiseService.selectById(id);
    }
    //唯一性校验
    @PostMapping("/nameunique")
    public R nameUnique(@RequestBody AdvertiseVoVo advertiseVoVo){
        return tbAdvertiseService.nameUnique(advertiseVoVo);
    }
    //图片上传
    @PostMapping("uploadpicture")
    public R uploadPicture(MultipartFile file){
        String s= null;
        try {
            s = UploadPicture.uploadPicture(file.getInputStream(),file.getOriginalFilename());
            return R.ok().put("path",s);
        } catch (IOException e) {
            e.printStackTrace();
            return R.error();
        }

    }
    /*//查询轮播图
    @PostMapping("/nameunique")
    public R nameUnique(@RequestBody TbAdvertise tbAdvertise){
        return tbAdvertiseService.selectImgs(tbAdvertise);
    }*/


}
